package tmi.li.txwidgets.txclck;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class TxClckTime {
	private Calendar cal; 
	private SimpleDateFormat hours12 = new SimpleDateFormat("h");  
    private SimpleDateFormat minutes = new SimpleDateFormat("m"); 
    private SimpleDateFormat hours24 = new SimpleDateFormat("k"); 
    
    //creating a calender instance when the TxClckTime obj is created
    //create a new one if u want the actual time 
	public TxClckTime() {
		cal = Calendar.getInstance();
	}
		
	
	//returning AM||PM 
	public String getDesc() {
		if(Integer.valueOf(hours24.format(cal.getTime()))> 11 && Integer.valueOf(hours24.format(cal.getTime()))< 24) {
			return "PM";
		}else {
			return "AM";
		}	    
	}
	
	//returning minutes
	public String getMinutes() {
		if(Integer.valueOf(minutes.format(cal.getTime()))< 10) {
	    	return "0"+minutes.format(cal.getTime());
	    }else {
	    	return minutes.format(cal.getTime());
	    }
	}
	
	
	//returning the hours, i = 0 => 12 hours format; i = 1 => 24 hours format;
	public String getHours(int i) {
		if( Integer.valueOf(hours24.format(cal.getTime())) == 24) {			
			return "0";
		}else {
			if( i == 0 ) {
				return hours12.format(cal.getTime());
			}else {
				return hours24.format(cal.getTime());
			}
		}
	}
		
}
